import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_base/12_bottomNavigationBar/home.dart';
import 'package:flutter_base/12_bottomNavigationBar/mine.dart';
import 'package:flutter_base/12_bottomNavigationBar/travel.dart';

import '../12_bottomNavigationBar/serch.dart';

class Tabbar2 extends StatefulWidget {
  const Tabbar2({super.key});

  @override
  State<Tabbar2> createState() => __tabbar2State();
}

class __tabbar2State extends State<Tabbar2> {
  List<Widget> listviews = const [
    Homepage1(),
    Mine1(),
    Search1(),
    Travel(),
    Search1(),
  ];

  int _currentIndex = 2;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: const Text('咸鱼按钮'),
      ),
      body: listviews[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex, // 默认选中的按钮
        fixedColor: Colors.orange, // 选中的按钮颜色
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
          BottomNavigationBarItem(
              icon: Icon(Icons.create_new_folder), label: '探索'),
          BottomNavigationBarItem(
              icon: Icon(Icons.backpack_outlined), label: '添加'),
          BottomNavigationBarItem(icon: Icon(Icons.track_changes), label: '消息'),
          BottomNavigationBarItem(icon: Icon(Icons.minor_crash), label: '我的'),
        ],
        type: BottomNavigationBarType.fixed,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
      ),
      floatingActionButton: Container(
        padding: const EdgeInsets.all(8),
        width: 60,
        height: 60,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(30),
        ),
        child: FloatingActionButton(
            backgroundColor: _currentIndex == 2 ? Colors.orange : Colors.grey,
            child: const Icon(Icons.add),
            onPressed: () {
              setState(() {
                _currentIndex = 2;
              });
            }),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    );
  }
}
